package com.example.zpositionanimationdemo.chechbox;

import ohos.agp.components.AttrSet;
import ohos.agp.components.Checkbox;
import ohos.agp.components.Component;
import ohos.app.Context;
import ohos.multimodalinput.event.TouchEvent;

/**
 * RCheckBox
 *
 * @author ZhongDaFeng
 */
public class RCheckBox extends Checkbox implements RHelper<RCheckHelper>, Component.TouchEventListener {
    private RCheckHelper mHelper;

    /**
     * RCheckBox
     *
     * @param context 上下文
     */
    public RCheckBox(Context context) {
        this(context, null);
    }

    /**
     * RCheckBox
     *
     * @param context 上下文
     * @param attrs attrs
     */
    public RCheckBox(Context context, AttrSet attrs) {
        super(context, attrs);
        mHelper = new RCheckHelper(context, this, attrs);
    }

    @Override
    public RCheckHelper getHelper() {
        return mHelper;
    }

    @Override
    public void setEnabled(boolean isEnabled) {
        super.setEnabled(isEnabled);
        if (mHelper != null) mHelper.setEnabled(isEnabled);
    }

    @Override
    public boolean onTouchEvent(Component component, TouchEvent event) {
        if (mHelper != null) mHelper.onTouchEvent(component, event);
        return super.getTouchEventListener().onTouchEvent(component, event);
    }

    @Override
    public void setSelected(boolean isSelected) {
        if (mHelper != null) mHelper.setSelected(isSelected);
        super.setSelected(isSelected);
    }

    @Override
    public void setChecked(boolean isChecked) {
        if (mHelper != null) mHelper.setChecked(isChecked);
        super.setChecked(isChecked);
    }
}
